package com.banzhi.shop.entity.videocollege;

import com.banzhi.shop.MyApp;

import com.banzhi.shop.state.URLString;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.LogUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.HttpMethod;
import org.xutils.http.RequestParams;
import org.xutils.x;

import cz.msebera.android.httpclient.protocol.HTTP;


/**
 * Created by Administrator on 2018/5/10.
 */

public class VideoCollegeImpl implements IVideoCollegeModel {
    @Override
    public void getData(int page, String type, final VideoCollegeCallBack callBack) {
        RequestParams params = new RequestParams(URLString.CollegeOrderURL);
        params.addBodyParameter("token", MyApp.loginMessage.getString("token", ""));
        params.addBodyParameter("page", page + "");
        params.addBodyParameter("type", type);
        LogUtils.d("VideoCollegeImpl", params.toString());
       // x.http().post(params, new Callback.CommonCallback<String>() {
        x.http().request(HttpMethod.POST,params,new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
             //   LogUtils.d("hththt",result.toString());
                try {
                    JSONObject jsonobject = new JSONObject(result);
                    if (jsonobject.optString("code").equals("0")) {
                        Gson gson = new Gson();
                        VideoOrder videoOrder = gson.fromJson(result, VideoOrder.class);
                //        callBack.ongetDataSuccess( videoOrder.getData());
                        callBack.ongetDataSuccess( videoOrder.getData().getList());
//                        ToastUtils.makeToastLong("dadada");
                    } else {
                        callBack.ongetDataError(jsonobject);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                LogUtils.e("ShouyijiluImpl", "---onError----" + ex.toString());
                LoadingDialogUtils.dismiss();
                ToastUtils.makeToastShort("网络加载失败,请稍后再试");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                LoadingDialogUtils.dismiss();
            }
        });
    }
}

